package com.jhx.demos.web.controller;

import com.jhx.demos.web.pojo.BufferMessage;
import com.jhx.demos.web.pojo.Result;
import com.jhx.demos.web.pojo.User;
import com.jhx.demos.web.service.bufferService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.nio.Buffer;
import java.util.List;

@Slf4j
@RequestMapping("/buffer")
@RestController


public class BufferController {

    @Autowired
    private bufferService bufferservice;

    @GetMapping
    //显示管理员审核留言信息
    public Result list() {
        log.info("显示待审核信息列表");
        List<BufferMessage> BM = bufferservice.list();
        return Result.success(BM);
    }

    @PutMapping
    //管理员进行审核信息
    public Result updateMessageStatus(@RequestBody BufferMessage bmes) {
        log.info("审核用户提交的留言, bmes",bmes);
        bufferservice.updateMessageStatus(bmes);
        return Result.success("审核信息成功");
    }


    //删除用户提交的留言
    @DeleteMapping("/{id}")
    public Result deleete(@PathVariable Integer id) {
        log.info("根据id删除信息:{}" + id);
        bufferservice.dellete(id);
        return Result.success();

    }

    //修改用户的权限，禁用及恢复
    @PutMapping("/manage")
    public Result manage(@RequestBody User user) {
        log.info("审核用户的账号状态, user{}", user);
        bufferservice.manage(user);
        return Result.success();
    }


    //将状态为一的数据插入进来
    @PutMapping ("/insert")
    public Result insert(){
        log.info("批量审核操作");
        bufferservice.insert();
        return Result.success();
    }

}
